#include "brpc.pb.h"
#include <thread>
#include <brpc/channel.h>

int main()
{
    brpc::Channel channel;
    brpc::ChannelOptions options;
    options.protocol="baidu_std";
    options.connection_type="";
    options.max_retry=3;
    options.connect_timeout_ms=1000;
    options.timeout_ms=-1;
    
    if(channel.Init("0.0.0.0:8989","",&options)!=0)
    {
        std::cerr<<"Init channel failed"<<std::endl;
    }
    example::EchoService_Stub stub(&channel);

    //int log_id=0;     //这一部分是日志信息，测试代码里我们暂且不关心。
    example::EchoResphone* resphone =new example::EchoResphone();
    brpc::Controller* ctrl=new brpc::Controller();
    while(!brpc::IsAskedToQuit())
    {
        example::EchoRequest request;
        
       request.set_message("Hello!");
       ctrl->request_attachment().append("binary sequence");
       stub.Echo(ctrl,&request,resphone,nullptr);

       
        std::cout<<ctrl->local_side()
        <<"accept remote message from: "<<ctrl->remote_side()
        <<" message: "<<resphone->message()
        <<" total echo time: "<<ctrl->latency_us()<<std::endl; 
       
       sleep(1);
       resphone->clear_message();
    }
    delete(resphone);
    delete(ctrl);
    return 0;
}